<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      h1 {
        color: red !important
      }
    </style>
  </head>
  <body>
    <h1>adsjfasjdfkasd</h1>
    <div id="box"></div>
    <script>
      // 结论解释打开控制台的会 console会造成内存泄漏， 不打开的话不会有任何影响
      const h1 = document.querySelector('h1')
      const box = document.getElementById('box');
      h1.onclick = function(e) {
        const MB = 1024 * 1024;
            log();

            function log() {
                const memory = performance.memory.totalJSHeapSize;
                const usagedMemory = Math.floor(memory / MB);
                box.insertAdjacentHTML('beforeend', `<span>${usagedMemory} </span>`);

                const obj = {usagedMemory, str: 'g'.repeat(50 * MB)};
                console.log(obj); 

                setTimeout(() => log(), 50);
            }
      }
    </script>
  </body>
</html>
